trigger NewUniqueAuthors on MZ_Track__c (after insert , after delete) {
    List<MZ_Playlist_Entry__c> tracks = [Select id, Name, MZ_Playlist_ref__c , MZ_Track_ref__r.MZ_Author_ref__c From MZ_Playlist_Entry__c  ];
    Map<id,Integer> trackMap = new Map<id,Integer> ();
    for(MZ_Playlist_Entry__c track: tracks){
        if(!trackMap.containsKey(track.MZ_Playlist_ref__c)){
            trackMap.put(track.MZ_Playlist_ref__c , 0);
        }
        trackMap.put(track.MZ_Playlist_ref__c , trackMap.get(track.MZ_Playlist_ref__c)+1);
    }
     for(MZ_Playlist__c playlist: [Select id, Name, MZ_Unique_Authors_Number__c From MZ_Playlist__c]){
         playlist.MZ_Unique_Authors_Number__c = trackMap.get(playlist.id);
     }
  
}